home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************\
- **
- ** DIGNET AREXX DEMO SCRIPT 1.0
- **
- **
- ** Copyright © 1997 by Digital Surface and Kenneth "Kenny" Nilsen
- ** Public domain.
- **
- **---------------------------------------------------------------------------
- **
- ** The arexx commands has the same names as the library function names.
- **
- ** NOTE WELL: Max length to read or write is 65536 bytes (64kb) length!
- ** Never ever use any length longer than this. You must buffer the
- ** read/write if you need longer lengths than this (this only complies
- ** to the arexx interface - not the library functions). This behaviour
- ** may change in the future.
- **
- \***************************************************************************/
-
-
- LF = '0a'x /* LineFeed chr(10)
- */
- CR = '0d'x /* Carriage Return chr(13)
- */
- Options RESULTS /* important or else we wount get net number
- */
- /* Load dignet.library into memory
- */
- IF ~show('p', 'DIGNET') then do
- address command
- "c:loadlib dignet.library"
- "WaitForPort DIGNET"
- END
-
- Address "DIGNET" /* arexx port of library
- --------------------------------*/
-
- /* Allocate a device and unit
- IMPORTANT: You must enquote the devicename
- or else AREXX will uppercase it. Device
- names are case-sensitive..
- */
- AllocNet "duart.device" 0
- Net=RESULT
- /* if RC isn't NULL there occured an error
- */
- IF (rc~=0) then do
- say "ERROR: Couldn't allocate this net! Check device name and unit.."
- exit 0
- END
-
- SAY LF||"- Allocated net number:" Net
-
-
- /* Now we'll do some stuff with the lib
- --------------------------------*/
-
- /* We will capture all IO into "ram:test.log
- */
-
- SAY "- Starting IO capturing of file 'ram:test.log'"
-
- CaptureTextStart '"'Net'"' 0 "ram:test.log"
- IF (rc~=0) then SAY "Couldn't capture to file!"
-
- /* Set default parameters
- */
- SetDefault '"'Net'"'
- IF (rc~=0) then say "Couldn't set default parameters to net!"
-
- /* Flush the net to clear buffers etc.
- */
- FlushNet '"'net'"'
- IF (rc~=0) then say "Couldn't flush the net!"
-
- /* Ok, lets assume we have a modem connected
- to the port. Will will try to send a
- command 'ATZ'to the modem..
- */
-
- SAY "- Sending 'ATZ' to the modem and waiting 1 second.."
-
- WriteString '"'Net'"' "ATZ"||CR
- IF (rc~=0) then do
- SAY "Error while writing to net!"
- SAY "Modem probably not connected..."
- FreeNet '"'Net'"'
- exit 0
- END /* Delay 1 second before testing feedback.
- The Timeout command returns immediatly if
- there is one or more bytes sent so the
- modem doesn't have enough time to send us
- all the datas...
- */
- Address Command 'c:wait 1'
-
- /* Wait for respons (an OK etc.) - give modem
- 2 seconds to answer
- */
- TimeOut '"'net'"' 2
- Bytes=RESULT
-
- SAY "- There are/is" bytes "byte(s) waiting to be read."
-
- IF Bytes=0 then do
- SAY "Error: Didn't get any respons from modem.. quiting!"
- FreeNet '"'Net'"'
- exit 0
- END
- /* now read the chars and print them to
- console
- */
-
- SAY "- Reading byte(s) and showing:"
-
- ReadNet '"'Net'"' '"'Bytes'"'
- IF (rc~=0) then SAY "An error occured while reading the net!"
-
- SAY RESULT /* Here we type the buffer
- */
- /* We don't want more capturing so stop it..
- */
- SAY "- Ending IO capture"
-
- CaptureTextEnd '"'Net'"'
- IF (rc~=0) then SAY "There was no capture file to stop.."
-
- /* Get some info
- */
- GetCurrentDevice '"'Net'"'
- Device=RESULT
-
- GetCurrentUnit '"'Net'"'
- Unit=RESULT
-
- SAY "- The net allocated is using the '"device"' unit '"unit"'"
-
- /* Get baudrate we're using
- */
- GetBaudrate '"'Net'"'
- baudrate=RESULT
-
- SAY "- Default baud speed is" baudrate "baud"
-
- /* Set a different baudrate
- */
-
- SAY "- We will change default baud rate to 57600 baud..."
-
- SetBaud '"'Net'"' 57600
-
- /* Show new baud rate
- */
- GetBaudrate '"'net'"'
- SAY "- New default baud speed is" RESULT "baud"
-
- /* be nice and set back to original baudrate
- */
-
- SAY "- We're nice so we'll set it back to" baudrate "baud"
-
- SetBaud '"'Net'"' '"'baudrate'"'
-
-
- /* Now free the net - we're done..
- --------------------------------*/
-
- SAY "Done!"
-
- FreeNet '"'Net'"' /* Enclose the net variable like this or else
- arexx will give the keyword 'net' instead
- of its contents (the netnumber)
- */
-
- /* Did we try to free a non existing net ?
- (asks resource tracking)
- */
-
- IF (rc=5) then SAY "Error: Net' Net 'was not allocated!"
-
- /* TIP: you can free other nets as well so be careful. You could use this
- "feature" in conjunction with resource tracking to write a simple RT tool
- f.ex: 1> rx "address dignet;freenet "<netnumber>" - that's it..
- BE POLITE!
-
- A protection feature may be integrated in the future to prevent this.
- */
-
- exit 0
-